package sctu.edu.java.year2016.team07.shihaocheng.day20160520.Chapter4_3;

/**
 * Created by admin on 2016/5/21.
 *用while循环计算1+1/2!+1/3!+……1/20！之和
 */

public class chapter4_3 {
    public static void main(String[] args) {
        int i = 1;
        int j = 1;
        int n = 1;
        float sum = 0f;
        float sum1 = 1f;
        while (n <= 20) {
            while (j <= i) {
                sum1 = sum1 * 1 / j;
                j++;
            }
            sum = sum + sum1;
            n++;
            i++;
        }

        System.out.println("sum" + sum);
    }
    }
